<?php

class conf {
	public function __construct( $defaults ) {
		foreach( $defaults as $cat => $opts ) {
			$this->$cat = new stdClass();
			foreach( $opts['items'] as $option )
				$this->$cat->{$option['name']} = $option['value'];
		}

		foreach( db()->select('base_conf') as $value )
			if( isset( $this->{$value['category']}->{$value['name']} ))
				$this->{$value['category']}->{$value['name']} = $value['value'];
	}

	public function set( $cat, $key, $value ) {
		if( $value != $this->$cat->$key ) {
				$this->$cat->$key  = $value;
				db()->insert ('base_conf', array(
						'category' => $cat,
						'name' => $key,
						'value' => $value,
				), 'REPLACE');
		}
	}
}

